package com.springboot.wisdom.system.controller;


import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import com.springboot.wisdom.common.common.bean.DeleteDTO;
import com.springboot.wisdom.common.common.bean.MyResult;
import com.springboot.wisdom.serviceApi.system.model.dto.DeptDTO;
import com.springboot.wisdom.system.service.DeptService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

@Api(tags = "系统管理模块【部门管理】")
@ApiSupport(author = "LY L")
@RestController
@RequestMapping(value = "/system/dept", produces = {"application/json;charset=UTF-8"})
@Slf4j
public class DeptController {

    @Resource
    private DeptService deptService;

    // 部门树。
    @ApiOperation(value = "部门树", notes = "")

    @GetMapping("/tree")
    public MyResult<List<?>> getTree(DeptDTO deptDTO){
        return deptService.getTree(deptDTO);
    }

    // 添加。
    @ApiOperation(value = "添加公司/部门", notes = "根据父ID判断子元素添加。")
    @PostMapping("/add")
    public MyResult<String> add(@RequestBody @Valid DeptDTO deptDTO){
        return deptService.add(deptDTO);
    }


    // 修改。
    @ApiOperation(value = "修改公司/部门", notes = "根据父ID判断子元素添加。")
    @PostMapping("/edit")
    public MyResult<String> edit(@RequestBody @Valid DeptDTO deptDTO){
        return deptService.edit(deptDTO);
    }

    // 删除。
    @ApiOperation(value = "单条删除", notes = "")
    @DeleteMapping("/delete/{id}")
    public MyResult<String> delete(@PathVariable String id){
        return deptService.delete(id);
    }
    // 删除树及其子元素。
    @ApiOperation(value = "树关联删除", notes = "")
    @DeleteMapping("/delete/tree/{id}")
    public MyResult<String> deleteTree(@PathVariable String id){
        return deptService.deleteTree(id);
    }
    // 批量删除。
    @ApiOperation(value = "批量删除", notes = "")
    @DeleteMapping("/delete")
    public MyResult<String> deleteList(@RequestBody @Validated DeleteDTO<String> dto){
        return deptService.deleteList(dto);
    }
}
